import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:osc/common/constants.dart';
import 'package:osc/data/api/api_service.dart';
import 'package:osc/data/api/apis.dart';
import 'package:osc/data/net/dio_util.dart';
import 'package:osc/common/osc_sp.dart';
import 'package:osc/common/osc_user_manager.dart';
import 'package:osc/models/entity/app_update_info.dart';
import 'package:osc/models/base_resp.dart';
import 'package:osc/models/entity/osc_active_list_entity.dart';
import 'package:osc/models/entity/osc_activity_entity.dart';
import 'package:osc/models/entity/osc_author.dart';
import 'package:osc/models/entity/osc_banner_entity.dart';
import 'package:osc/models/entity/osc_base_entity.dart';
import 'package:osc/models/entity/osc_base_list_entity.dart';
import 'package:osc/models/entity/osc_blog_comment_list_entity.dart';
import 'package:osc/models/entity/osc_blog_detail_entity.dart';
import 'package:osc/models/entity/osc_blog_entity.dart';
import 'package:osc/models/entity/osc_blog_list_entity.dart';
import 'package:osc/models/entity/osc_comment_list_entity.dart';
import 'package:osc/models/entity/osc_company_soft_list_entity.dart';
import 'package:osc/models/entity/osc_event_list_entity.dart';
import 'package:osc/models/entity/osc_favorite_item.dart';
import 'package:osc/models/entity/osc_favorite_list_entity.dart';
import 'package:osc/models/entity/osc_favorite_reverse_result_entity.dart';
import 'package:osc/models/entity/osc_find_entity.dart';
import 'package:osc/models/entity/osc_friends_list_entity.dart';
import 'package:osc/models/entity/osc_medal_entity.dart';
import 'package:osc/models/entity/osc_message_letter_entity.dart';
import 'package:osc/models/entity/osc_message_list_entity.dart';
import 'package:osc/models/entity/osc_message_mention_entity.dart';
import 'package:osc/models/entity/osc_news_detail_entity_1.dart';
import 'package:osc/models/entity/osc_news_list_entity.dart';
import 'package:osc/models/entity/osc_notice.dart';
import 'package:osc/models/entity/osc_oauth_token.dart';
import 'package:osc/models/entity/osc_open_source_company_entity.dart';
import 'package:osc/models/entity/osc_post_detail_entity.dart';
import 'package:osc/models/entity/osc_post_entity.dart';
import 'package:osc/models/entity/osc_post_list_entity.dart';
import 'package:osc/models/entity/osc_comment_entity.dart';
import 'package:osc/models/entity/osc_comment_result_entity.dart';
import 'package:osc/models/entity/osc_project_detail_entity.dart';
import 'package:osc/models/entity/osc_question.dart';
import 'package:osc/models/entity/osc_read_record.dart';
import 'package:osc/models/entity/osc_reverse_relation_entity.dart';
import 'package:osc/models/entity/osc_search_result_entity.dart';
import 'package:osc/models/entity/osc_skill_radar_map_entity.dart';
import 'package:osc/models/entity/osc_soft_banner_entity.dart';
import 'package:osc/models/entity/osc_project_catalog_list_entity.dart';
import 'package:osc/models/entity/osc_project_list_entity.dart';
import 'package:osc/models/entity/osc_soft_list_entity.dart';
import 'package:osc/models/entity/osc_soft_recommend_list_entity.dart';
import 'package:osc/models/entity/osc_topic_detail_entity.dart';
import 'package:osc/models/entity/osc_tweet_comment_entity.dart';
import 'package:osc/models/entity/osc_tweet_like_list_entity.dart';
import 'package:osc/models/entity/osc_tweet.dart';
import 'package:osc/models/entity/osc_tweet_like_reverse_entity.dart';
import 'package:osc/models/entity/osc_update_relation_entity.dart';
import 'package:osc/models/entity/osc_user_blog_list_entity.dart';
import 'package:osc/models/entity/osc_user.dart';
import 'package:osc/models/entity/osc_user_tag.dart';
import 'package:osc/utils/string_util.dart';

class HttpRepository {

  static const int PAGE_SIZE = Constant.PAGE_SIZE;
  String accessToken;
  String dataType = "json";

  String accessTokenKey = "access_token";
  String dataTypeKey = "dataType";
  String pageSizeKey = "pageSize";
  String pageKey = "page";
  String relationKey = "relation";
  String idKey = "id";
  String identKey = "ident";
  String catalogKey = "catalog";
  String tagKey = "tag";
  String userKey = "user";
  String userIdKey = "userId";
  String authorUidKey = "authoruid";
  String authorIdKey = "authorId";
  String authorNameKey = "authorname";
  String typeKey = "type";
  String pageTokenKey = "pageToken";
  String sourceIdKey = "sourceId";
  String replyIdKey = "replyId";
  String orderKey = "order";
  String contentKey = "content";

  int pageSize = 20;
  int userId;

  var data;
  FormData formData;


  factory HttpRepository() => getInstance();
  static HttpRepository get instance => getInstance();
  static HttpRepository _instance;

  HttpRepository._internal() {
    // 初始化
    userId = OscUserManager().userId;
    accessToken = OscSp().getAccessToken();
    pageSize = Constant.PAGE_SIZE;
    data =  {
      accessTokenKey:accessToken,
      dataTypeKey:dataType,
    };
    formData = FormData.from(data);
  }
  static HttpRepository getInstance() {
    if (_instance == null) {
      _instance = new HttpRepository._internal();
    }
    return _instance;
  }

  /// 检查更新
  Future<BaseResp<AppUpdateInfo>> checkUpdate() async {
    Response response = await DioUtil().request(
      Method.get, Api.GET_APP_VERSION_INFO
    );
    return BaseResp<AppUpdateInfo>(response, (res)=>AppUpdateInfo.fromJson(res));
  }

  //------------------------------ OSC --------------------------------
  /// authorization_code 方式获取 AccessToken
  /// 引方法只能把参数放在 url中，不能放入在Form，否则把500，java.lang.String cannot be cast to [Ljava.lang.String
  Future<OscOauthToken> getOauth2Token({String code, bool isRefreshToken = false, String refreshToken}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Constant.GET_OSC_OPEN_API_OAUTH2_TOKEN_URL(code:code, isRefreshToken: isRefreshToken, refreshToken: refreshToken),
    );
    OscOauthToken token = OscOauthToken(response);
    if(token.accessToken != null){
      OscSp oscSp = OscSp.instance;
      oscSp.setAccessToken(token.accessToken);
      oscSp.setRefreshToken(token.refreshToken);
      oscSp.setTokenType(token.tokenType);
      oscSp.setExpiresIn(token.expiresIn);
      oscSp.setUId(token.uid);
      OscUserManager().setLogin(true);
      OscUserManager().setUId(token.uid);
      OscUserManager().setUserId(token.uid);
      OscUserManager().setAccessToken(token.accessToken);
      OscUserManager().setRefreshToken(token.refreshToken);
      OscUserManager().setTokenType(token.tokenType);
      OscUserManager().setExpiresIn(token.expiresIn);
    }
    return token;
  }

  /// 登录返回用户详情
  Future<OscBaseEntity<OscUser>> login({@required String account, @required String password}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_LOGIN,
      queryParameters: FormData.from({
        "account":account,//查询用户id
        "password":password,
      }),
    );
    return OscBaseEntity<OscUser>(response, (res) => OscUser.fromJson(res));
  }

  ///我的消息
  ///isAtMe true @我, false 评论
  Future<OscBaseListEntity<OscMessageMentionEntity>> getUserMassages({@required bool isAtMe, String pageToken = ""}) async {
    Response response = await DioUtil()
        .request(Method.get,
      isAtMe? Api.OSC_OPEN_API_USER_MESSAGE_MENTIONS : Api.OSC_OPEN_API_USER_MESSAGE_COMMENTS,
    );
    return OscBaseListEntity<OscMessageMentionEntity>(response, (res) => OscMessageMentionEntity.fromJson(res));
  }

  ///我的私信
  Future<OscBaseListEntity<OscMessageLetterEntity>> getMyMassageLetters({String pageToken = ""}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_USER_MESSAGE_LETTERS,
    );
    return OscBaseListEntity<OscMessageLetterEntity>(response, (res) => OscMessageLetterEntity.fromJson(res));
  }

  ///黑名单
  Future<OscBaseListEntity<OscAuthor>> getBlacklist({@required int id, String pageToken = ""}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_BLACKLIST,
      queryParameters: FormData.from({
        pageTokenKey:pageToken,
        idKey:id,
      }),
    );
    return OscBaseListEntity<OscAuthor>(response, (res) => OscAuthor.fromJson(res));
  }

  ///黑名单
  Future<OscBaseEntity<bool>> reverseBlack({@required int id}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLACK_REVERSE,
      data: FormData.from({
        "blackId":id,
      }),
    );
    return OscBaseEntity<bool>(response, null, isBoolResult: true);
  }

  ///勋章
  Future<OscBaseListEntity<OscMedal>> getMedalist({int type = 1, @required int userId}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_USER_MEDAL,
      queryParameters: FormData.from({
        typeKey:type,
        idKey:userId,
      }),
    );
    return OscBaseListEntity<OscMedal>(response, (res) => OscMedal.fromJson(res));
  }

  ///阅读记录
  Future<OscBaseListEntity<OscReadRecord>> getReadRecords() async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_READ_RECORD,
    );
    return OscBaseListEntity<OscReadRecord>(response, (res) => OscReadRecord.fromJson(res));
  }

  /// 当前用户登录账户信息
  /*Future<BaseResp<OscUserEntity>> getUser() async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_USER,
      data: formData,
    );
    return BaseResp<OscUserEntity>(response, (res) => OscUserEntity.fromJson(res));
  }*/

  /// 用户详情
  /*Future<BaseResp<OscUserInfoEntity>> getUserInfos({@required int userId, int friendId, String friendName}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_USER_INFORMATION,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        "user":userId,//查询用户id
        "friend":friendId,//被查询用户id（friend和friend_name必须存在一个）
        "friend_name":friendName  //被查询用户ident或名称
      }),
    );
    return BaseResp<OscUserInfoEntity>(response, (res) => OscUserInfoEntity.fromJson(res));
  }*/

  /// 用户详情
  Future<OscBaseEntity<OscUser>> getUserInfoV2({@required int userId, String nickName}) async {
    Map<String, dynamic> map = Map();
    if(userId != null){
      map[idKey] = userId;
    }
    if(!StringUtil.isEmpty(nickName)){
      map["nickname"] = nickName;
    }
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_USER_INFO_V2,
//      queryParameters: FormData.from({
//        idKey:userId,//查询用户id
//        "nickname":nickName,
//      }),
      queryParameters: map,
    );
    return OscBaseEntity<OscUser>(response, (res) => OscUser.fromJson(res));
  }

  /// 个人主页详情
  /*Future<BaseResp<OscUserInfoEntity>> getMyInfos() async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_MY_INFORMATION,
      data: formData,
    );
    return BaseResp<OscUserInfoEntity>(response, (res) => OscUserInfoEntity.fromJson(res));
  }*/

  /// 个人主页技能雷达
  Future<BaseResp<OscSkillRadarMapEntity>> getSkillRadarMap(int userId) async {
    Response response = await DioUtil()
        .request(Method.post,
      "/u/$userId/${Api.OSC_OPEN_API_USER_PORTRAIT_RADAR_MAP}",
      data: {
          userIdKey: userId,
        "skillsNum":5,
      },
    );
    return BaseResp<OscSkillRadarMapEntity>(response, (res) => OscSkillRadarMapEntity.fromJson(res));
  }

  /// 头像更新
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> updatePortrait(String filePath) async {
    File file = File(filePath);
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_PORTRAIT_UPDATE,
      data: FormData.from({
        accessTokenKey:accessToken,
        "img":file  //用户头像
      }),
    );
    return BaseResp(response, null);
  }

  /// 获取好友列表
  /// relation 0-粉丝|1-关注的人
  Future<BaseResp<OscFriendsListEntity>> getFriendList({int page = 1, int relation = 0}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_FRIENDS_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        pageSizeKey:pageSize,
        relationKey:relation
      }),
    );
    return BaseResp<OscFriendsListEntity>(response, (res) => OscFriendsListEntity.fromJson(res));
  }

  /// 获取粉丝/关注列表
  Future<OscBaseListEntity<OscUser>> getUserFriendList({@required bool fans, String pageToken = "", int userId,}) async {
    Response response = await DioUtil()
        .request(Method.get,
      fans?Api.OSC_OPEN_API_FANS_LIST : Api.OSC_OPEN_API_FOLLOWS_LIST,
      queryParameters: FormData.from({
        pageTokenKey:pageToken,
        idKey:userId
      }),
    );
    return OscBaseListEntity<OscUser>(response, (res) => OscUser.fromJson(res));
  }


  /// 更新好友关系（加关注、取消关注）
  /// id 对方用户id
  Future<OscBaseEntity<OscReverseRelationEntity>> reverseRelation({@required int id}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_USER_RELATION_REVERSE,
      data: FormData.from({
        idKey:id
      }),
    );
    return OscBaseEntity<OscReverseRelationEntity>(response, (res) => OscReverseRelationEntity.fromJson(res));
  }

  /// 更新好友关系（加关注、取消关注）
  /// friendId 对方用户id
  /// relation 0-取消关注，1-加关注
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp<OscUpdateRelationEntity>> updateUserRelation(int friendId, int relation) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_UPDATE_USER_RELATION,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        "friend":friendId,
        relationKey:relation
      }),
    );
    return BaseResp<OscUpdateRelationEntity>(response, (res) => OscUpdateRelationEntity.fromJson(res));
  }

  /// 动态列表
  /// catalog 类别ID [ 0、1、4所有动态,2提到我的（消息中心--@我）,3评论我的动态（消息中心--评论）,4我的动弹 ]
  /// 其实0、1、4是一样的
  Future<BaseResp<OscActiveListEntity>> getActiveList({int page = 1, int catalog = 1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_ACTIVE_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        pageSizeKey:pageSize,
        "catalog":catalog,
        "user":userId
      }),
    );
    return BaseResp<OscActiveListEntity>(response, (res) => OscActiveListEntity.fromJson(res));
  }

  /// 获取banner
  /// catalog 1-资讯banner|4-博客banner|7-软件banner
  Future<BaseResp<OscBannerEntity>> getBanner({int catalog = 1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BANNER,
      data: FormData.from({
        catalogKey:catalog
      }),
    );
    return BaseResp<OscBannerEntity>(response, (res) => OscBannerEntity.fromJson(res));
  }

  /// 综合-资讯、推荐、问答、博客
  Future<OscBaseListEntity<OscPostEntity>> getSubListByToken({@required String token, String pageToken}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_SBU_LIST,
      queryParameters: FormData.from({
        "token":token,
        pageTokenKey:pageToken,
      }),
    );
    return OscBaseListEntity<OscPostEntity>(response, (res) => OscPostEntity.fromJson(res));
  }

  /// 评论
  Future<OscBaseEntity<OscCommentResultEntity>> comment({@required int id, int replyId = 0, @required String content, @required int type, int reAuthorId = 0}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_COMMENT_PUSH,
      data: FormData.from({
        sourceIdKey:id,
        replyIdKey:replyId,
        contentKey:content,
        typeKey:type,
        "reAuthorId":reAuthorId,
      }),
    );
    return OscBaseEntity<OscCommentResultEntity>(response, (res) => OscCommentResultEntity.fromJson(res));
  }

  /// 获取新闻列表
  /// catalog 1-所有(资讯)|2-综合新闻|3-软件更新
  Future<BaseResp<OscNewsListEntity>> getNewsList({int page = 1, int catalog = 1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_NEWS_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        pageSizeKey:pageSize,
        catalogKey:catalog
      }),
    );
    return BaseResp<OscNewsListEntity>(response, (res) => OscNewsListEntity.fromJson(res));
  }

  /// 获取新闻详情
  /// id 新闻编号
  Future<BaseResp<OscNewsDetailEntity_1>> getNewsDetail(int id) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_NEWS_DETAIL,
      data: FormData.from({
        accessTokenKey:accessToken,//传则显示是否收藏 用户未登录则不传
        dataTypeKey:dataType,
        idKey:id
      }),
    );
    return BaseResp<OscNewsDetailEntity_1>(response, (res) => OscNewsDetailEntity_1.fromJson(res));
  }

  /// 获取问答列表
  Future<OscBaseListEntity<OscQuestion>> getQuestionList({String pageToken = "", int catalog = 0, int userId,}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_QUESTION_LIST,
      queryParameters: FormData.from({
        pageTokenKey:pageToken,
        authorIdKey:userId,
        catalogKey:catalog
      }),
    );
    return OscBaseListEntity<OscQuestion>(response, (res) => OscQuestion.fromJson(res));
  }

  /// 获取活动列表
  Future<OscBaseListEntity<OscEventListEntity>> getEventList({String pageToken = "", @required int userId,}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_EVENT_LIST,
      queryParameters: FormData.from({
        pageTokenKey:pageToken,
        authorIdKey:userId,
      }),
    );
    return OscBaseListEntity<OscEventListEntity>(response, (res) => OscEventListEntity.fromJson(res));
  }

  /// 获取讨论列表
  Future<OscBaseListEntity<OscActivityEntity>> getActivityList({String pageToken = "", int userId,}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_ACTIVITY_LIST,
      queryParameters: FormData.from({
        pageTokenKey:pageToken,
        idKey:userId,
      }),
    );
    return OscBaseListEntity<OscActivityEntity>(response, (res) => OscActivityEntity.fromJson(res));
  }

  /// 关注标签列表
  Future<OscBaseListEntity<OscUserTag>> getUserTagList() async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_USER_TAGS,
    );
    return OscBaseListEntity<OscUserTag>(response, (res) => OscUserTag.fromJson(res));
  }

  /// 搜索标签列表
  Future<OscBaseListEntity<OscUserTag>> searchTagList({@required String name, String pageToken}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_SEARCH_TAG_BY_NAME,
      data: FormData.from({
        "keyword":name,
        pageTokenKey:pageToken,
      })

    );
    return OscBaseListEntity<OscUserTag>(response, (res) => OscUserTag.fromJson(res));
  }

  /// 删除标签
  Future<OscBaseEntity> updateTagRelation({@required int id, bool delete}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_UPDATE_TAG_RELATION,
      data: FormData.from({
        delete?"deleteIds":"ids":id,
      }),
    );
    return OscBaseEntity(response, null);
  }

  /// 获取讨论区的帖子列表(对应android的 问答 分享 综合 职业 站务
  /// catalog 类别ID 1-问答 2-分享 3-IT杂烩(综合) 4-站务 100-职业生涯 0-所有
  /// tag 帖子相关标签
  /// catalog 与 tag 不同时使用，使用 tag 则为获取标签相关列表，使用 catalog 则列出分类列表。
  Future<BaseResp<OscPostListEntity>> getPostList({int page = 1, int catalog = 0, String tag}) async {
    Map<String, dynamic> map = {
      accessTokenKey:accessToken,
      dataTypeKey:dataType,
      pageKey:page,
      pageSizeKey:pageSize,
    };
    if(StringUtil.isEmpty(tag)){
      map[catalogKey] = catalog;
    } else {
      map[tagKey] = tag;
    }
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_POST_LIST,
      data: FormData.from(map),
    );
    return BaseResp<OscPostListEntity>(response, (res) => OscPostListEntity.fromJson(res));
  }

  /// 发布帖子
  /// title 标题
  /// content 帖子内容
  /// isNoticeMe 有回答是否邮件通知 2是邮件通知
  /// askUserId 用户id（向某人提问）
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> publishPost(int catalog, String title, String content, {int isNoticeMe = 0, int askUserId}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_POST_PUB,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        catalogKey:catalog,
        "title":title,
        "content":content,
        "isNoticeMe":isNoticeMe,
        "askuser":askUserId
      }),
    );
    return BaseResp(response, null);
  }

  /// 获取讨论区的帖子详情
  Future<OscBaseEntity<OscPostDetailEntity>> getPostDetail({@required int id, @required int type}) async {
    Response response = await _getDetailByType(id: id, type: type);
    return OscBaseEntity<OscPostDetailEntity>(response, (res) => OscPostDetailEntity.fromJson(res));
  }

  /// 获取动弹列表 （最新动弹列表 热门动弹）
  /// type  [ 1：最新动弹，2：热门动弹 ]，与authorId相斥，只传一个
  /// authorId [用户id动态, ]
  /// pageToken [上一次请求返回的下一页请求 token,首次请求不填]
  Future<OscBaseListEntity<OscTweet>> getTweetList({int type, int authorId, String pageToken}) async {
    Map<String, dynamic> map = Map();
    if(type != null){
      map[typeKey] = type;
    }
    if(authorId != null){
      map[authorIdKey] = authorId;
    }
    if(!StringUtil.isEmpty(pageToken)){
      map[pageTokenKey] = pageToken;
    }
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_TWEET_LIST,
      queryParameters: FormData.from(map),
    );
    return OscBaseListEntity<OscTweet>(response, (res) => OscTweet.fromJson(res));
  }

  /// 获取话题动弹列表
  /// type 1:最新|2:最热
  Future<OscBaseListEntity<OscTweet>> getTopicTweetList({int topicId = 0, String name, int type = 1, String pageToken}) async {
    Map<String, dynamic> map = Map();
    map[typeKey] = type;
    map["topicId"] = topicId;
    map["name"] = name;
    if(!StringUtil.isEmpty(pageToken)){
      map[pageTokenKey] = pageToken;
    }
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_TOPIC_TWEET_LIST,
      queryParameters: map,
    );
    return OscBaseListEntity<OscTweet>(response, (res) => OscTweet.fromJson(res));
  }

  /// 获取推荐话题列表
  Future<OscBaseListEntity<OscTopicDetailEntity>> getRecommendTopicList() async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_TOPIC_RECOMMEND,
    );
    return OscBaseListEntity<OscTopicDetailEntity>(response, (res) => OscTopicDetailEntity.fromJson(res));
  }

  /// 获取话题
  Future<OscBaseEntity<OscTopicDetailEntity>> getTopicDetail({int topicId = 0, String name}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_TOPIC_DETAIL,
      queryParameters: {
        "topicId":topicId,
        "name":name,
      },
    );
    return OscBaseEntity<OscTopicDetailEntity>(response, (res) => OscTopicDetailEntity.fromJson(res));
  }

  /// 获取动弹点赞列表
  /// pageToken [上一次请求返回的下一页请求 token,首次请求不填或""]
  Future<OscBaseListEntity<OscTweetLike>> getTweetLikeList({@required int tweetId, String pageToken = ""}) async {
    Map<String, dynamic> map = Map();
    map[sourceIdKey] = tweetId;
    map[pageTokenKey] = pageToken;
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_TWEET_LIKE_LIST,
      queryParameters: FormData.from(map),
    );
    return OscBaseListEntity<OscTweetLike>(response, (res) => OscTweetLike.fromJson(res));
  }

  /// 获取动弹点赞列表
  /// pageToken [上一次请求返回的下一页请求 token,首次请求不填或""]
  /// order 当等于1时为精彩评论
  Future<OscBaseListEntity<OscTweetComment>> getTweetCommentList({@required int tweetId, String pageToken = "", int order = 0}) async {
    Map<String, dynamic> map = Map();
    map[sourceIdKey] = tweetId;
    map[pageTokenKey] = pageToken;
    if(order == 1){
      map[orderKey] = order;
    }
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_TWEET_COMMENT_LIST,
      queryParameters: FormData.from(map),
    );
    return OscBaseListEntity<OscTweetComment>(response, (res) => OscTweetComment.fromJson(res));
  }

  /// 点赞动弹
  /// sourceId 动弹id
  Future<OscBaseEntity<OscTweetLikeReverseEntity>> reverseTweetLike({@required int sourceId}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_TWEET_LIKE_REVERSE,
      data: FormData.from({
        sourceIdKey: sourceId,
      }),
    );
    return OscBaseEntity<OscTweetLikeReverseEntity>(response, (res) => OscTweetLikeReverseEntity.fromJson(res));
  }

  /// 评论动弹
  /// sourceId 动弹id
  Future<OscBaseEntity<OscTweetComment>> commentTweet({@required int sourceId, @required String content}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_TWEET_COMMENT,
      data: FormData.from({
        sourceIdKey: sourceId,
        contentKey:content,
      }),
    );
    return OscBaseEntity<OscTweetComment>(response, (res) => OscTweetComment.fromJson(res));
  }

  /// 发布动弹
  /// content 动弹内容
  /// imgPath 图片路径
  /// 错误代码（200-操作成功，500-操作失败）
  Future<OscBaseEntity<OscTweet>> publishTweet({@required String content, int aboutFromTweetId = 0,
    int aboutId = 0, int aboutType = 0, String imgPath}) async {
    Map<String, dynamic> map = Map();
    map["content"] = content;
    map["aboutFromTweetId"] = aboutFromTweetId;
    map["aboutId"] = aboutId;
    map["aboutType"] = aboutType;
    if(!StringUtil.isEmpty(imgPath)){
      map["img"] = imgPath;
    }
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_TWEET_PUB,
      data: FormData.from(map),
    );
    return OscBaseEntity<OscTweet>(response, (res) => OscTweet.fromJson(res));
  }

  /// 删除动弹
  Future<OscBaseEntity> deleteTweet(int id) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_TWEET_DELETE,
      data: FormData.from({
        sourceIdKey : id,
      }),
    );
    return OscBaseEntity(response, null);
  }


  /// 获取博客列表
  Future<BaseResp<OscBlogListEntity>> getBlogList({int page = 1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLOG_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        pageSizeKey:pageSize
      }),
    );
    return BaseResp<OscBlogListEntity>(response, (res) => OscBlogListEntity.fromJson(res));
  }

  /// 获取博客推荐列表(对应 app博客)
  Future<BaseResp<OscBlogListEntity>> getBlogRecommendList({int page = 1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLOG_RECOMMEND_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        pageSizeKey:pageSize
      }),
    );
    return BaseResp<OscBlogListEntity>(response, (res) => OscBlogListEntity.fromJson(res));
  }

  /// 获取博客详情
  Future<BaseResp<OscBlogDetailEntity>> getBlogDetail(int id) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLOG_DETAIL,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        idKey:id
      }),
    );
    return BaseResp<OscBlogDetailEntity>(response, (res) => OscBlogDetailEntity.fromJson(res));
  }

  /// 获取用户博客列表
  /// authorUid  用户ID(authorUid authorName任选一种)
  /// authorName 用户Ident(authorUid authorName任选一种)
  Future<BaseResp<OscUserBlogListEntity>> getUserBlogList({int page = 1,int authorUid, String authorName}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_USER_BLOG_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        pageSizeKey:pageSize,
        authorUidKey:authorUid,
        authorNameKey:authorName
      }),
    );
    return BaseResp<OscUserBlogListEntity>(response, (res) => OscUserBlogListEntity.fromJson(res));
  }

  /// 获取用户博客列表
  /// authorUid  用户ID(authorUid authorName任选一种)
  /// authorName 用户Ident(authorUid authorName任选一种)
  Future<OscBaseListEntity<OscBlogEntity>> getUserBlogListV2({String pageToken = "", int authorId}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_USER_BLOG,
      queryParameters: FormData.from({
        pageTokenKey:pageToken,
        authorIdKey:authorId,
      }),
    );
    return OscBaseListEntity<OscBlogEntity>(response, (res) => OscBlogEntity.fromJson(res));
  }

  /// 获取博客分类列表
  /// authorUid  用户ID(authorUid authorName任选一种)
  /// authorName 用户Ident(authorUid authorName任选一种)
  Future<BaseResp<OscUserBlogListEntity>> getBlogCatalogList(int page,{int authorUid, String authorName}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLOG_CATALOG_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        authorUidKey:authorUid,
        authorNameKey:authorName
      }),
    );
    return BaseResp<OscUserBlogListEntity>(response, (res) => OscUserBlogListEntity.fromJson(res));
  }

  ///获取博客评论列表
  /// id 博客id
  Future<BaseResp<OscBlogCommentListEntity>> getBlogCommentList(int id, int page) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLOG_COMMENT_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        idKey:id,
        pageSizeKey:pageSize
      }),
    );
    return BaseResp<OscBlogCommentListEntity>(response, (res) => OscBlogCommentListEntity.fromJson(res));
  }

  /// 发布博客评论
  /// content 回复内容
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> publishBlogComment(int blogId, String content) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLOG_COMMENT_PUB,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        "blog":blogId,
        "content":content
      }),
    );
    return BaseResp(response, null);
  }

  ///回复博客评论
  /// content 回复内容
  /// replyId 被回复评论id
  /// replyUserId 被回复评论的发布者id
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> replyBlogComment(int blogId, String content, int replyId, int replyUserId) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_BLOG_COMMENT_REPLY,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        "blog":blogId,
        "content":content,
        "reply_id":replyId,
        "reply_user":replyUserId
      }),
    );
    return BaseResp(response, null);
  }

  ///删除用户博客
  /// blogId 博客id
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> deleteUserBlog(int blogId) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_USER_BLOG_DELETE,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        idKey:blogId
      }),
    );
    return BaseResp(response, null);
  }

  ///获取评论列表
  /// id  新闻ID/翻译ID/帖子ID/动弹ID/用户ID（私信中跟当前用户来往的ID）/博客ID
  /// catalog  1-新闻/翻译|2-帖子|3-动弹|4-消息(私信 必须access_token)|5-博客
  /// catalog为4的时候 查看私信列表必须提供access_token
  Future<BaseResp<OscCommentListEntity>> getCommentList11({int id, int catalog, int page = 1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_COMMENT_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        idKey:id,
        catalogKey:catalog,
        pageSizeKey:pageSize
      }),
    );
    return BaseResp<OscCommentListEntity>(response, (res) => OscCommentListEntity.fromJson(res));
  }

  ///发表评论
  /// content 回复内容
  /// id 将要评论的id
  /// catalog 表示将对哪一种元素类型发表评论， 1 -- 新闻 2 -- 帖子 3 -- 动弹 4 -- 消息中心的消息
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> publishComment(int id, String content, int catalog) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_COMMENT_PUB,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        idKey:id,
        catalogKey:catalog,
        "content":content
      }),
    );
    return BaseResp(response, null);
  }

  ///回复评论
  /// catalog 评论对象类型：1-新闻或翻译，2-帖子、问答，3-动弹，4-私信
  /// content 回复内容
  /// receiverId 被回复者id:要回复的此条评论的发布者的用户id
  /// authorId 被回复者id:要回复的此条评论的发布者的用户id
  /// replyId 被回复评论id:当前要回复的评论的id
  /// isPostToMyZone 动弹是否转发到我的空间，1-转发，0-不转发。catalog 为 3 使用
  /// 注意事项
  /// 1、catalog = 1 时：id 大于 10000000 则为翻译，所需参数为：access_token，id，catalog，content，authorid，replyid
  /// 2、catalog = 2 时，所需参数：access_token，id，catalog，content
  /// 3、catalog = 3 时，所需参数：access_token，id，catalog，content，authorid
  /// 4、catalog = 4 时，所需参数：access_token，catalog，content，authorid此时 id 为非必须
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> replyComment(int id, int catalog, String content, {int receiverId, authorId, int replyId, int isPostToMyZone}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_COMMENT_REPLY,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        idKey:id,
        catalogKey:catalog,
        "content":content,
        "receiver":receiverId,
        authorUidKey:authorId,
        "replyid":replyId,
        "isPostToMyZone":isPostToMyZone
      }),
    );
    return BaseResp(response, null);
  }

  ///删除评论
  /// id 对象id:新闻、翻译id，帖子id，动弹id
  /// catalog 评论对象类型：1-新闻或翻译，2-帖子、问答，3-动弹，4-私信
  /// authorId 回复的此条评论的发布者的用户id
  /// replyId 当前要回复的评论的id
  /// 注意事项
  /// 1、catalog = 1 时：id 大于 10000000 则为翻译，所需参数为：access_token，id，replyid
  ///                  id小于10000000 则是新闻，所需参数为：access_token，id，replyid，authorid
  /// 2、catalog = 2 时，所需参数：access_token，id，authorid，replyid
  /// 3、catalog = 3 时，所需参数：access_token，id，replyid
  /// 4、catalog = 4 时，所需参数：access_token，id或replyid（id或replayid都为私信id）
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> deleteComment(int id, int catalog, authorId, int replyId) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_COMMENT_DELETE,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        idKey:id,
        catalogKey:catalog,
        authorUidKey:authorId,
        "replyid":replyId
      }),
    );
    return BaseResp(response, null);
  }

  ///获取收藏列表
  /// type  0-全部|1-软件|2-话题|3-博客|4-新闻|5代码|7-翻译
  Future<BaseResp<OscFavoriteListEntity>> getFavoriteList(int type, int page) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_FAVORITE_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        typeKey:type,
        pageSizeKey:pageSize
      }),
    );
    return BaseResp<OscFavoriteListEntity>(response, (res) => OscFavoriteListEntity.fromJson(res));
  }

  ///获取收藏列表
  /// catalog  0-全部|1-软件|2-话题|3-博客|4-新闻|5代码|7-翻译
  Future<OscBaseListEntity<OscFavoriteItem>> getFavoriteListV2({int catalog = 0, String pageToken = ""}) async {
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_FAVORITE_LIST_V2,
      queryParameters: FormData.from({
        pageTokenKey:pageToken,
        catalogKey:catalog,
      }),
    );
    return OscBaseListEntity<OscFavoriteItem>(response, (res) => OscFavoriteItem.fromJson(res));
  }

  ///收藏反转
  /// type 被收藏对象类型 [1-软件,2-帖子（问答、话题）,3-博客,4-资讯,5-代码,6-资讯,7-翻译]
  Future<OscBaseEntity<OscFavoriteReverseResultEntity>> favoriteReverse({@required int id, @required int type}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_FAVORITE_REVERSE,
      data: FormData.from({
        idKey:id,
        typeKey:type,
      }),
    );
    return OscBaseEntity<OscFavoriteReverseResultEntity>(response, (res) => OscFavoriteReverseResultEntity.fromJson(res));
  }

  /// 添加收藏
  /// id 被收藏对象id
  /// type 被收藏对象类型 [1-软件,2-帖子（问答、话题）,3-博客,4-资讯,5-代码,7-翻译]
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> addFavorite(int id, int type) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_FAVORITE_ADD,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        idKey:id,
        typeKey:type
      }),
    );
    return BaseResp(response, null);
  }

  /// 取消收藏
  /// id 被收藏对象id
  /// type 被收藏对象类型 [1-软件,2-帖子（问答、话题）,3-博客,4-资讯,5-代码,7-翻译]
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> removeFavorite(int id, int type) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_FAVORITE_REMOVE,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        idKey:id,
        typeKey:type
      }),
    );
    return BaseResp(response, null);
  }

  /// 评论软件
  Future<OscBaseEntity<OscCommentResultEntity>> commentSoft({@required int id, int replyId = 0, @required String content}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_PROJECT_COMMENT_PUSH,
      data: FormData.from({
        sourceIdKey:id,
        replyIdKey:replyId,
        contentKey:content,
      }),
    );
    return OscBaseEntity<OscCommentResultEntity>(response, (res) => OscCommentResultEntity.fromJson(res));
  }

  /// 获取软件详情
  Future<OscBaseEntity<OscProjectDetail>> getSoftDetail({int id, String ident}) async {
    Response response = await _getDetailByType(id: id, type: 1, ident: ident);
    return OscBaseEntity<OscProjectDetail>(response, (res) => OscProjectDetail.fromJson(res));
  }

  /// 获取资讯、博客、软件详情
  /// type 0-所有(打开url)|1-软件|2-问答|3-博客|4-翻译|5活动|6资讯|7-
   _getDetailByType({int id, @required int type, String ident}) async {
    Map<String, dynamic> map = Map();
    map[typeKey] = type;
    if(id != null && id > -1){
      map[idKey] = id;
    }
    if(!StringUtil.isEmpty(ident)){
      map[identKey] = ident;
      map["key"] = "osc_1_0";
    }
    Response response = await DioUtil()
        .request(Method.get,
      Api.OSC_OPEN_API_DETAIL,
//      queryParameters: FormData.from(map),
      queryParameters: map,
    );
    return response;
  }

  /// 获取软件分类列表(只有2级)
  /// tag  第一级:tag传0,第二级:传递第一级返回的对应tag
  Future<BaseResp<OscProjectCatalogListEntity>> getProjectCatalogList({int tag = 0}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_PROJECT_CATALOG_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        tagKey:tag
      }),
    );
    return BaseResp<OscProjectCatalogListEntity>(response, (res) => OscProjectCatalogListEntity.fromJson(res));
  }

  /// 软件分类下的的软件列表
  /// type  recommend-推荐(对应 app软件 banner,各两条重复数据)|time-最新(对应最新软件)|view-热门|cn-国产
  Future<BaseResp<OscProjectListEntity>> getProjectList({String type = "recommend"}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_PROJECT_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        typeKey:type
      }),
    );
    return BaseResp<OscProjectListEntity>(response, (res) => OscProjectListEntity.fromJson(res));
  }

  ///软件 banner
  Future<BaseResp<OscSoftBannerEntity>> getProjectBanner() async {
    Response response = await ApiService.getOscH5Api()
        .request(Method.get,
      Api.OSC_OPEN_API_PROJECT_BANNER,
    );
    return BaseResp<OscSoftBannerEntity>(response, (res) => OscSoftBannerEntity.fromJson(res));
  }

  ///软件公司
  Future<BaseResp<OscOpenSourceCompanyEntity>> getOpenSourceCompanyList() async {
    Response response = await ApiService.getOscH5Api()
        .request(Method.get,
      Api.OSC_OPEN_API_PROJECT_OPEN_SOURCE_COMPANIES,
    );
    return BaseResp<OscOpenSourceCompanyEntity>(response, (res) => OscOpenSourceCompanyEntity.fromJson(res));
  }

  /// 公司软件列表
  Future<BaseResp<OscCompanySoftListEntity>> getCompanyProjectList({int companyId, int page = 1}) async {
    Response response = await ApiService.getOscH5Api()
        .request(Method.get,
      Api.OSC_OPEN_API_PROJECT_COMPANY_PROJECT_LIST,
      queryParameters: {
        pageKey:page,
        pageSizeKey:pageSize,
        idKey: companyId,
      },
    );
    return BaseResp<OscCompanySoftListEntity>(response, (res) => OscCompanySoftListEntity.fromJson(res));
  }

  /// 软件推荐列表
  Future<BaseResp<OscSoftRecommendListEntity>> getProjectRecommendList({int page = 1}) async {
    Map<String, dynamic> map = {
      pageKey:page,
      pageSizeKey:pageSize
    };
    Response response = await ApiService.getOscH5Api()
        .request(Method.get,
      Api.OSC_OPEN_API_PROJECT_RECOMMEND,
      queryParameters: map,
    );
    return BaseResp<OscSoftRecommendListEntity>(response, (res) => OscSoftRecommendListEntity.fromJson(res));
  }

  /// 软件分类列表
  /// catalog 2:热门国产, 3:最新软件
  Future<BaseResp<OscSoftListEntity>> getProjectListByCatalog({int catalog = 2, int companyId, int page = 1}) async {
    String path;
    switch(catalog){
      case 2:
        path = Api.OSC_OPEN_API_PROJECT_HOT_CN;
        break;
      case 3:
        path = Api.OSC_OPEN_API_PROJECT_LATEST;
        break;
    }
    Response response = await ApiService.getOscH5Api()
        .request(Method.get,
      path,
      queryParameters: {
        pageKey:page,
        pageSizeKey:pageSize
      },
    );
    return BaseResp<OscSoftListEntity>(response, (res) => OscSoftListEntity.fromJson(res));
  }

  /// Tag下的软件列表
  /// tagId，project_tag_list中的得到的tag
  Future<BaseResp<OscProjectListEntity>> getProjectTagList({String tagId = "0"}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_PROJECT_TAG_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        tagKey:tagId
      }),
    );
    return BaseResp<OscProjectListEntity>(response, (res) => OscProjectListEntity.fromJson(res));
  }

  /// 评论列表
  Future<OscBaseListEntity<OscCommentEntity>> getCommentList({@required int id, @required int type, String pageToken = "", int order = 1}) async {
    Response response = await DioUtil()
        .request(Method.get,
      type == 1? Api.OSC_OPEN_API_PROJECT_COMMENT_LIST : Api.OSC_OPEN_API_COMMENT_LIST,
      queryParameters: FormData.from({
        "sourceId":id,
        pageTokenKey:pageToken,
        "order":order,
        "parts":"refer,reply",
        typeKey:type,
      }),
    );
    return OscBaseListEntity<OscCommentEntity>(response, (res) => OscCommentEntity.fromJson(res));
  }

  /// 发现
  Future<BaseResp<OscFindEntity>> getFind() async {
    Response response = await ApiService.getOscH5Api()
        .request(Method.get,
      Api.OSC_OPEN_API_FIND,
    );
    return BaseResp<OscFindEntity>(response, (res) => OscFindEntity.fromJson(res));
  }

  /// 获取私信列表
  Future<BaseResp<OscMessageListEntity>> getMessageList(int page) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_MESSAGE_LIST,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        pageKey:page,
        pageSizeKey:pageSize
      }),
    );
    return BaseResp<OscMessageListEntity>(response, (res) => OscMessageListEntity.fromJson(res));
  }

  /// 删除私信
  /// userId 发送私信者
  /// friendId 接受私信者
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> deleteMessage(int userId, int friendId) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_MESSAGE_DELETE,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        userKey:userId,
        "friend":friendId
      }),
    );
    return BaseResp(response, null);
  }

  /// 获取搜索列表
  /// keyword 搜索关键字
  /// order 0-按相关度|3-按时间
  /// type -1:软件+用户+文章|0:文章|1:软件
  Future<OscBaseEntity<OscSearchResultEntity>> searchArticle({String pageToken = "", @required String keyword, int order = 0, int type = -1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_SEARCH_ARTICLE,
      data: FormData.from({
        pageTokenKey:pageToken,
        "keyword":keyword,
        orderKey:order,
        typeKey:type,
      }),
    );
    return OscBaseEntity<OscSearchResultEntity>(response, (res) => OscSearchResultEntity.fromJson(res));
  }

  /// 搜索
  /// keyword 搜索关键字
  /// catalog 11:用户
  Future<OscBaseListEntity<OscUser>> searchUser({String pageToken = "", @required String keyword, int catalog = 11}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_SEARCH,
      data: FormData.from({
        pageTokenKey:pageToken,
        contentKey:keyword,
        catalogKey:catalog,
      }),
    );
    return OscBaseListEntity<OscUser>(response, (res) => OscUser.fromJson(res));
  }

  /// 获取用户通知
  Future<BaseResp<OscNotice>> getUserNotice() async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_USER_NOTICE,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType
      }),
    );
    return BaseResp<OscNotice>(response, (res) => OscNotice.fromJson(res));
  }

  /// 删除通知
  /// type 需清除的通知类型：
  /// 1-清除 @我的信息(referCount)，
  /// 2-清除 未读信息(msgCount)，
  /// 3-清除 评论个数(replyCount)，
  /// 4-清除 新粉丝个数(fansCount)
  /// 错误代码（200-操作成功，500-操作失败）
  Future<BaseResp> clearNotice({int type = 1}) async {
    Response response = await DioUtil()
        .request(Method.post,
      Api.OSC_OPEN_API_MESSAGE_DELETE,
      data: FormData.from({
        accessTokenKey:accessToken,
        dataTypeKey:dataType,
        userKey:userId,
        typeKey:type
      }),
    );
    return BaseResp(response, null);
  }
}